# -*- coding: utf-8 -*-
# @Time    : 2018/8/1 13:12
# @Author  : Tianchiyue
# @File    : word_cloud.py
# @Software: PyCharm Community Edition

import jieba.analyse
from rake_nltk import Rake
from flask import send_file
from wordcloud import WordCloud,ImageColorGenerator
from PIL import Image
import numpy as np

COLORING = np.array(Image.open("src/template.jpg"))


def get_image(sentence_list, mode='rake', language='en'):
    """
    :param sentence_list:
    :param mode:tfidf, textrank, rake
    :param language: english, chinese
    :return:
    """
    text = ' '.join(sentence_list)
    wc = WordCloud(background_color='white', max_words=20, mask=COLORING)
    wc.generate(text)
    wc.to_file('src/wordcloud.png')
    return send_file('src/wordcloud.png', mimetype='image/png')
    # with open('src/template.jpg','rb') as f:
    #     image_rb = f.read()
    # return image_rb